<?php

class CronicasController extends BaseController {

	/*
	|--------------------------------------------------------------------------
	| Default Home Controller
	|--------------------------------------------------------------------------
	|
	| You may wish to use controllers instead of, or in addition to, Closure
	| based routes. That's great! Here is an example controller method to
	| get you started. To route to this controller, just add the route:
	|
	|	Route::get('/', 'HomeController@showWelcome');
	|
	*/

	public function index()
	{
		$cronicas = Cronica::orderBy('created_at')->paginate(3);
		
		return View::make('contents.cronicas',compact('cronicas'))->with('title','Cronicas :: Paintballed');
	}

	public function cronica($id){
		$cronica = Cronica::find($id);
		
		$data=array('cronica'=>$cronica);
		
		$validator = Validator::make(Input::all(), array(
				'comentario'=>'required'
		));
		
		if($validator->passes()){
			$comentario= new Comentario();
			$comentario->contenido=Input::get('comentario');
		
			Auth::user()->comentarios()->save($comentario);
		
			$cronica->comentarios()->attach($comentario);
		}
		
		return View::make('contents.cronica',$data)->with('title','Cronica '.$id.' :: Paintballed');
	}
}